<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/17
  Time: 16:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>

<body>
<%

    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String dataBasePassword = null;

    //JDBC 3+1
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;

    String sql = "select * from t_users where name="+username;


    Class.forName("com.mysql.jdbc.Driver");

    connection = DriverManager.getConnection(

            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?characterEncoding=utf-8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC",
            "root",
            "123456"
    );

    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);

    if(resultSet.next()){
        dataBasePassword = resultSet.getString("password");
    }

    resultSet.close();
    statement.close();
    connection.close();


    if (password.equals(dataBasePassword)){

        session.setAttribute("isLogin","true");

        //登录成功后跳转到首页
        response.sendRedirect("index.jsp");
    }else {
        out.write("登录失败");
    }

%>
</body>
</html>
